using System;
using System.Reflection; // Necesario pra extender una clase

namespace Serpis
{
	public static class MemberInfoExtensions
	{
		public static TAttribute GetAttribute<TAttribute>(this MemberInfo memberInfo) where TAttribute : Attribute
		{
			return (TAttribute)Attribute.GetCustomAttribute(memberInfo, typeof(TAttribute), true);
		}
		
		public static bool IsDefined<TAttribute>(this MemberInfo memberInfo)
		{
			return Attribute.IsDefined(memberInfo, typeof(TAttribute), true);
		}
		
		//	decora la clase y retorna la etiqueta de ésta
		public static string GetLabel(this MemberInfo memberInfo)
		{
			if(!memberInfo.IsDefined<LabelAttribute>())
			{
				return memberInfo.Name;
			}
			LabelAttribute labelAttribute = memberInfo.GetAttribute<LabelAttribute>();
			return labelAttribute.Label;

		}
	}
}
